package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.TbOPProductPlanView;
import com.sl.au.repository.ProductPlanRepository;
import com.sl.au.service.ProductPlanService;
@Service("ProductPlanService")
@Transactional
public class ProductPlanServiceImpl extends BaseServiceImpl implements ProductPlanService{

	@Autowired
	ProductPlanRepository productPlanRepository;
	
	@Override
	public List<TbOPProductPlanView> getMyPage(int start, int length, String key) {
		Page<TbOPProductPlanView> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"dIssueDate");//排序
		if(key == null ){
			pages=productPlanRepository.getPage(pageable);
		}else{
			pages=productPlanRepository.getPage(key, pageable);
		}
		return pages.getContent();
	}

	@Override
	public long getCount(String key) {
		// TODO Auto-generated method stub
		long count = 0;
		if(key == null){
			count = productPlanRepository.getCount();
		}else{
			count = productPlanRepository.getCount(key);
		}
		return count;
	}

	@Override
	public ProductPlanRepository getRepository() {
		// TODO Auto-generated method stub
		return this.productPlanRepository;
	}

}
